﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjetSMA.Model
{
    public class Path : GenericNode
    {
        private Element m_position;
        private Element m_cible ;
        private ItemMove m_item;

        public Path(GenericNode par_parent, Element par_position, Element par_cible,  ItemMove par_item)
        {
            m_position = par_position;
            m_cible = par_cible;
            m_item = par_item;

            m_parent = par_parent;
            m_listTransition = new List<Transition>();
            m_nomNoeud = par_position.Name;

            m_costHeuristique = System.Math.Sqrt(Math.Pow(m_position.I - m_cible.I, 2) + (Math.Pow(m_position.J - m_cible.J, 2)));
        }

        public override string NomNoeud 
        { 
            get { return m_nomNoeud; }
            set { m_nomNoeud = value; }
        }
        public override double MyCost 
        {
            get { return m_cost; }
            set { m_cost = value; } 
        }
        public override double MyCostHeuristique 
        {
            get { return m_costHeuristique; }
            set { m_costHeuristique = value; }
        }
        public override double MyTotalCost 
        {
            get { return m_totalCost; }
            set { m_totalCost = value; }
        }
        public override bool Visited {
            get { return m_visited; }
            set { m_visited = value; }
        }
        public override GenericNode Parent {
            get { return m_parent; }
            set { m_parent = value; }
        }
        public override double GetArcCost()
        {
            return System.Math.Sqrt(Math.Pow(m_position.I - m_cible.I, 2) + (Math.Pow(m_position.J - m_cible.J, 2)));
        }
        public override List<GenericNode> GetListSucc()
        {
            List<GenericNode> loc_succ = new List<GenericNode>();

            for (int i = 0; i < m_position.Neighboors.Count; i++)
            {
                if (m_item.TestVisited(m_position.Neighboors[i]))
                {
                    loc_succ.Add(new Path(this,m_position.Neighboors[i],m_cible,m_item));
                }
            }

            return loc_succ;
        }

        public override bool EndState()
        {
            if (m_position == m_cible)
                return true;
            return false;
        }

        public Element Position
        {
            get { return m_position; }
            set { m_position = value; }
        }

        public Element Cible
        {
            get { return m_cible; }
            set { m_cible = value; }
        }

       

    }
}
